public class AddMapObjectOperation extends MapMemory
{
    private static final long serialVersionUID = -1555791558720647704L;
    private int objectPos;

    public AddMapObjectOperation(MapObject object, int objectPos, MapPanel enclosingPanel)
    {
	super(object, enclosingPanel);
	this.objectPos = objectPos;
    }

    @Override
    public void undo()
    {
	this.enclosingPanel.setDisplayMap(((MapObject) this.value).getMap());
	
	// must update the reference to the object as it might have been edited and changed
	this.value = this.enclosingPanel.getMap().getMapObjects().get(this.objectPos);
	this.enclosingPanel.getMap().getMapObjects().remove(this.value);
    }

    @Override
    public void redo()
    {
	this.enclosingPanel.setDisplayMap(((MapObject) this.value).getMap());
	// can only undo in order of adding, so order stays the same
	this.enclosingPanel.getMap().getMapObjects().add((MapObject) this.value);
    }

}
